//
//  MPGuideViewController.m
//  M800Project
//
//  Created by 姚宗超 on 14/11/5.
//  Copyright (c) 2014年 姚宗超. All rights reserved.
//

#import "MPGuideViewController.h"
#import "Masonry.h"

@interface MPGuideViewController ()
@property (nonatomic, strong)UIImageView* bgImageView;
@property (nonatomic, strong)UIImageView* logoImageView;
@property (nonatomic, strong)UIButton* newerBtn;
@property (nonatomic, strong)UIButton* incomeBtn;
@property (nonatomic, strong)UIButton* efficiencyBtn;
@property (nonatomic, strong)UIButton* skipBtn;

@property (nonatomic, copy)guideViewCompletionHandler completionHandler;

@end

@implementation MPGuideViewController

- (instancetype)initWithCompletionHandler:(guideViewCompletionHandler)handler
{
    if (self = [super init]) {
        self.completionHandler = handler;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view addSubview:self.bgImageView];
    [self.view addSubview:self.logoImageView];
    [self.view addSubview:self.newerBtn];
    [self.view addSubview:self.incomeBtn];
    [self.view addSubview:self.efficiencyBtn];
    [self.view addSubview:self.skipBtn];
    
    [self setupConstraints];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)setupConstraints
{
    [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.leading.trailing.mas_equalTo(self.view);
    }];
    
    [self.logoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view).with.offset(74.0f);
        make.centerX.mas_equalTo(self.view);
    }];
    
    [self.newerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.logoImageView.mas_bottom).with.offset(80.0f);
        make.centerX.mas_equalTo(self.view);
        make.width.mas_equalTo(@(250.0f));
        make.height.mas_equalTo(@(50.0f));
    }];
    
    [self.incomeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.newerBtn.mas_bottom);
        make.height.width.centerX.mas_equalTo(self.newerBtn);
    }];
    
    [self.efficiencyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.incomeBtn.mas_bottom);
        make.height.width.centerX.mas_equalTo(self.incomeBtn);
    }];
    
    [self.skipBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self.newerBtn);
        make.bottom.mas_equalTo(self.view).with.offset(-20.0f);
    }];
}

#pragma mark - property
- (UIImageView *)bgImageView
{
    if (!_bgImageView) {
        _bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageForKey:@"bg_welcome"]];
    }
    return _bgImageView;
}

- (UIImageView *)logoImageView
{
    if (!_logoImageView) {
        _logoImageView = [[UIImageView alloc] initWithImage:[UIImage imageForKey:@"logo_welcome"]];
    }
    return _logoImageView;
}

- (UIButton *)newerBtn
{
    if (!_newerBtn) {
        _newerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_newerBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_newerBtn setBackgroundImage:[UIImage imageForKey:@"btn_bg_top_default"] forState:UIControlStateNormal];
        [_newerBtn setBackgroundImage:[UIImage imageForKey:@"btn_bg_top_focused"] forState:UIControlStateHighlighted];
        [_newerBtn setTitle:@"新手上路" forState:UIControlStateNormal];
        [_newerBtn setTitle:@"新手上路" forState:UIControlStateHighlighted];
        [_newerBtn addTarget:self action:@selector(newerBtnPressed:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _newerBtn;
}

- (void)newerBtnPressed:(id)sender
{
    KDLogTrace();
    if (self.completionHandler) {
        self.completionHandler(eMPVisitorSubscribeTypeNewer);
    }
}

- (UIButton *)incomeBtn
{
    if (!_incomeBtn) {
        _incomeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_incomeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_incomeBtn setBackgroundImage:[UIImage imageForKey:@"btn_bg_middle_default"] forState:UIControlStateNormal];
        [_incomeBtn setBackgroundImage:[UIImage imageForKey:@"btn_bg_middle_focused"] forState:UIControlStateHighlighted];
        [_incomeBtn setTitle:@"收益为王" forState:UIControlStateNormal];
        [_incomeBtn setTitle:@"收益为王" forState:UIControlStateHighlighted];
        [_incomeBtn addTarget:self action:@selector(incomeBtnPressed:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _incomeBtn;
}

- (void)incomeBtnPressed:(id)sender
{
    KDLogTrace();
    if (self.completionHandler) {
        self.completionHandler(eMPVisitorSubscribeTypeIncome);
    }
}

- (UIButton *)efficiencyBtn
{
    if (!_efficiencyBtn) {
        _efficiencyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_efficiencyBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_efficiencyBtn setBackgroundImage:[UIImage imageForKey:@"btn_bg_bottom_default"] forState:UIControlStateNormal];
        [_efficiencyBtn setBackgroundImage:[UIImage imageForKey:@"btn_bg_bottom_focused"] forState:UIControlStateHighlighted];
        [_efficiencyBtn setTitle:@"快进快出" forState:UIControlStateNormal];
        [_efficiencyBtn setTitle:@"快进快出" forState:UIControlStateHighlighted];
        [_efficiencyBtn addTarget:self action:@selector(efficiencyBtnPressed:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _efficiencyBtn;
}

- (void)efficiencyBtnPressed:(id)sender
{
    KDLogTrace();
    if (self.completionHandler) {
        self.completionHandler(eMPVisitorSubscribeTypeEfficient);
    }
}

- (UIButton *)skipBtn
{
    if (!_skipBtn) {
        _skipBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _skipBtn.backgroundColor = [UIColor clearColor];
        [_skipBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_skipBtn setTitle:@" > 跳过" forState:UIControlStateNormal];
        [_skipBtn addTarget:self action:@selector(skipBtnPressed:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _skipBtn;
}

- (void)skipBtnPressed:(id)sender
{
    KDLogTrace();
    if (self.completionHandler) {
        self.completionHandler(eMPVisitorSubscribeTypeDefault);
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
